<!--内置交互启动器-->

<template>
  <div class="w-h-full">
    <!--组件遮罩层，用于在设计器中显示-->
    <div v-if="shade" class="shade"></div>

    <div class="w-h-full" :style="{
      backgroundImage: 'url('+iconImg+')',
      backgroundRepeat: 'no-repeat',
      backgroundSize: '180px',
      backgroundPosition: 'center'
    }"/>

  </div>
</template>

<script>

  import FuncCompMixin from '@/mixin/FuncCompMixin'
  import PnDesigner from '@/utils/PnDesigner'

  const _this = {
    name: 'LaunchInteractionStreamComp', // 此名称必须填写，且必须与组件文件名相同
    mixins: [FuncCompMixin],
    attr: {
      version: '1.0',
      configDataTemp: Object.assign({

        launchQueue: [

        ]

      }, PnDesigner.buildFuncCompGlobalField(), PnDesigner.buildFuncCompInteractionConfiguration([
        PnDesigner.buildFuncCompInteractionStreamItem('',[

        ])
      ]))
    },
    data() {
      return {
        timeoutList: []
      }
    },
    destroyed() {
      this.$EventBus.$off('pn_layout_render_complete')

      if (this.timeoutList) {
        this.timeoutList.forEach(item => {
          clearTimeout(item)
        })
      }
    },
    mounted() {
      this.$EventBus.$on('pn_layout_render_complete', ()=>{
        this.init()
      })
    },
    methods: {
      init () { // 组价初始化函数，函数名必须使用init，不可更改
        if (this.$store.state.release.pageMetadata) {
          this.component.compConfigData.launchQueue.forEach((item, index) => {
            if (item.type == 'default') {
              if (item.bindingVariateName) {
                this.timeoutList[index] = setTimeout(()=>{
                  let value = undefined
                  eval(item.value)
                  this.$PnUtil.manualLaunchInteractionStream(item.bindingVariateName, value)
                }, item.delay)
              }
            }else if (item.type == 'custom') {
              if (item.customCode) {
                eval(item.customCode)
              }
            }
          })
        }
      }
    },
    computed: {
      iconImg () {
        return require('./images/icon.png');
      }
    }
  };

  export default _this
</script>

<style scoped>

</style>
